;; ;;; Enable helm-gtags-mode
;; (add-hook 'c-mode-hook 'helm-gtags-mode)
;; (add-hook 'c++-mode-hook 'helm-gtags-mode)
;; (add-hook 'asm-mode-hook 'helm-gtags-mode)

;; ;; customize
;; (custom-set-variables
;;  '(helm-gtags-path-style 'relative)
;;  '(helm-gtags-ignore-case t)
;;  '(helm-gtags-auto-update t))

;; ;; key bindings
;; (with-eval-after-load 'helm-gtags
;;   (define-key helm-gtags-mode-map (kbd "M-g M-a") 'helm-gtags-find-tag)
;;   (define-key helm-gtags-mode-map (kbd "M-t") 'helm-gtags-find-pattern)
;;   (define-key helm-gtags-mode-map (kbd "M-r") 'helm-gtags-find-rtag)
;;   (define-key helm-gtags-mode-map (kbd "M-s") 'helm-gtags-find-symbol)
;;   (define-key helm-gtags-mode-map (kbd "M-g M-p") 'helm-gtags-parse-file)
;;   (define-key helm-gtags-mode-map (kbd "M-[") 'helm-gtags-previous-history)
;;   (define-key helm-gtags-mode-map (kbd "M-]") 'helm-gtags-next-history)
;;   (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
;;   (define-key helm-gtags-mode-map (kbd "M-j") 'helm-gtags-find-tag-from-here))
;;============================c begins====================================;;
(defun my-c-mode-hook()
  ;;c++编写文件的快捷键（edited by very lazy Lazycal)
  (local-set-key (kbd "C-c C-f")
				 (lambda ()
				   (interactive)
				   (insert "#ifndef __" (upcase (replace-regexp-in-string (regexp-quote ".") "_" (filename))) "__")
				   (newline-and-indent)
				   (insert "#define __" (upcase (replace-regexp-in-string (regexp-quote ".") "_" (filename))) "__")
				   (newline-and-indent)
				   (insert "#endif")
				   )
				 )
  (local-set-key [f8] (lambda()
						(interactive )
						(shell-command "make run"))
				 )
  )
;;============================c ends====================================;;

;;============================c++ begins====================================;;
(defun my-c++-mode-hook()
										;(setq filename (buffer-name))
										;(setq filename_non_extension (substring filename 0 (string-match (regexp-quote ".") filename)))
  ;; (local-set-key [f7]
  ;; 				 '(lambda()
  ;; 					(interactive)
  ;; 					(compile (concat "g++ " (filename_non_extension) ".cpp -o " (filename_non_extension) " -g -Wall && gnome-terminal -e ./" (filename_non_extension)
  ;; 					))
  ;; 					)
  ;; 				 )
  ;;c++编写文件的快捷键（edited by very lazy Lazycal)
  (local-set-key (kbd "C-c C-f")
										;(define-key c++-mode-base-map (kbd "C-c C-f")
				 (lambda ()
				   (interactive)
				   (insert "#ifndef ONLINE_JUDGE")
				   (newline-and-indent)
				   (insert "freopen(\"" (filename_non_extension) ".in\",\"r\",stdin);")
				   (newline-and-indent)
				   (insert "freopen(\"" (filename_non_extension) ".out\",\"w\",stdout);")
				   (newline-and-indent)
				   (insert "#endif")
				   (newline-and-indent)
				   )
				 )
  (local-set-key [f8] (lambda()
						(interactive )
						(shell-command "make run"))
				 )
  )
(defun my-c++-oi-mode-hook()
										;(setq filename (buffer-name))
										;(setq filename_non_extension (substring filename 0 (string-match (regexp-quote ".") filename)))
  ;; (local-set-key [f7]
  ;; 				 '(lambda()
  ;; 					(interactive)
  ;; 					(compile (concat "g++ " (filename_non_extension) ".cpp -o " (filename_non_extension) " -g -Wall && gnome-terminal -e ./" (filename_non_extension)
  ;; 					))
  ;; 					)
  ;; 				 )
  ;;c++编写文件的快捷键（edited by very lazy Lazycal)
  (local-set-key (kbd "C-c C-f")
										;(define-key c++-mode-base-map (kbd "C-c C-f")
				 (lambda ()
				   (interactive)
				   (insert "#ifndef ONLINE_JUDGE")
				   (newline-and-indent)
				   (insert "freopen(\"" (filename_non_extension) ".in\",\"r\",stdin);")
				   (newline-and-indent)
				   (insert "freopen(\"" (filename_non_extension) ".out\",\"w\",stdout);")
				   (newline-and-indent)
				   (insert "#endif")
				   (newline-and-indent)
				   )
				 )
  (local-set-key [f8] (lambda()
						(interactive )
						(shell-command (concat "./" (filename_non_extension))))
				 )
  (local-set-key (kbd "C-c o")
				 (lambda()
				   (interactive )
				   (split-window-vertically)
				   (find-file (concat (filename_non_extension) ".out"))
				   )
				 )
  (local-set-key (kbd "C-c i")
				 (lambda()
				   (interactive )
				   (split-window-vertically)
				   (find-file (concat (filename_non_extension) ".in")))
				 )
  )
;;============================c++ ends====================================;;

;;============================pascal begins====================================;;
(defun my-pascal-mode-hook()
										;(setq filename (buffer-name))
										;(setq filename_non_extension (substring filename 0 (string-match (regexp-quote ".") filename)))
  (setq-default compile-command (concat "fpc " (filename_non_extension) ".pas"))
  (local-set-key [C-f2]
				 (lambda()
				   (interactive )
				   (split-window-vertically)
				   (find-file (concat (filename_non_extension) ".out")))
				 )
  (local-set-key [C-f1]
				 (lambda()
				   (interactive )
				   (split-window-vertically)
				   (find-file (concat (filename_non_extension) ".in")))
				 )
  )  
;;============================pascal ends====================================;;
;;============================python begins====================================;;
(defun my-python-mode-hook()
  (local-set-key (kbd "C-<return>") 'newline-and-indent)
  )
;;============================python ends====================================;;
(provide 'my-mode-hooks) 
